
/*
 * Replication Code
 * Paper: Provincial deficits and political centralization
 * Journal: Japanese Journal of Political Science
 * Input: ranking.dta, membership.dta
 * Output: pr_ranking1.gph, pr_ranking2.gph, pr_ranking3.gph, pr_membership.gph
 *		   pr_ranking1.png, pr_ranking2.png, pr_ranking3.png, pr_membership.png
 * Authors: Yang Zhang and Xi Wang
 * Date: May 9, 2021
 */


cd "/Users/Zhang/Dropbox Backup/activeProjects/shared/Local_Leaders/JJPS/Final/Replication"
 
set more off
 
/* Table 1: ordered logistic regression analysis of rankings */

use ranking, clear

global control "age male minority seniority experience1 experience2 work_units tie3 tie4"

ologit ranking c.tie1##c.deficit $control, cluster(province)
estimates store m1

ologit ranking c.tie1##c.deficit $control if ranking >= 3, cluster(province)
estimates store m2

ologit ranking c.tie2##c.deficit $control, cluster(province)
estimates store m3

ologit ranking c.tie2##c.deficit $control if ranking >= 3, cluster(province)
estimates store m4

estout m1 m2 m3 m4, cell(b (star fmt(4)) se (par fmt(4))) ///
	stats(N ll pr2) starl(* .05 ** .01)

/* Figure 1: Estimated effect of birthplace ties on rankings */

* Set up the covariates

clear
set obs 1

gen age = 52
gen male = 1
gen minority = 0
gen seniority = 64
gen experience1 = 48
gen experience2 = 15
gen work_units = 1
gen tie3 = 0.4
gen tie4 = 0.3

expand 301
gen deficit = _n - 1
gen id = _n

expand 6
bysort id: gen tie1 = _n - 1
gen inter = deficit * tie1

sort id deficit tie1

gen pred = 1

compress
save temp, replace

* Estimate the probabilities of different rankings

use ranking, clear

recode ranking 1/2=1 3/7=2 8/15=3, gen(ranking3)

global control "age male minority seniority experience1 experience2 work_units tie3 tie4"

ologit ranking3 c.tie1##c.deficit $control, cluster(province)

append using temp

predict p1, outcome(1) 
predict p2, outcome(2) 
predict p3, outcome(3) 

erase temp.dta

* Visualize the estimated probabilities of rankings

bysort province: gen deficit_rc = deficit if _n == 1
replace deficit_rc = 300 if !missing(deficit_rc) & deficit_rc >= 300

twoway hist deficit_rc, width(20) frequency yaxis(2) bcolor(navy*.2) ///
	|| line p1 deficit if tie1 == 5 & pred == 1, lwidth(0.6) lcolor(red*1) ///
	|| line p1 deficit if tie1 == 4 & pred == 1, lwidth(0.6) lcolor(red*.9) ///
	|| line p1 deficit if tie1 == 3 & pred == 1, lwidth(0.6) lcolor(red*.7) ///
	|| line p1 deficit if tie1 == 2 & pred == 1, lwidth(0.6) lcolor(red*.5) ///
	|| line p1 deficit if tie1 == 1 & pred == 1, lwidth(0.6) lcolor(red*.3) ///
	|| line p1 deficit if tie1 == 0 & pred == 1, lwidth(0.6) lcolor(red*0.1) ///
	legend(off) graphregion(color(white)) ///
	xtitle("Deficit") ytitle("Number of Provinces", axis(2)) ytitle("Probability of Ranking", axis(1)) ///
	xlabel(0 (50) 300)
graph save pr_ranking1.gph, replace
graph export pr_ranking1.png, replace
	
twoway hist deficit_rc, width(20) frequency yaxis(2) bcolor(navy*.2) ///
	|| line p2 deficit if tie1 == 5 & pred == 1, lwidth(0.6) lcolor(red*1) ///
	|| line p2 deficit if tie1 == 4 & pred == 1, lwidth(0.6) lcolor(red*.9) ///
	|| line p2 deficit if tie1 == 3 & pred == 1, lwidth(0.6) lcolor(red*.7) ///
	|| line p2 deficit if tie1 == 2 & pred == 1, lwidth(0.6) lcolor(red*.5) ///
	|| line p2 deficit if tie1 == 1 & pred == 1, lwidth(0.6) lcolor(red*.3) ///
	|| line p2 deficit if tie1 == 0 & pred == 1, lwidth(0.6) lcolor(red*0.1) ///
	legend(off) graphregion(color(white)) ///
	xtitle("Deficit") ytitle("Number of Provinces", axis(2)) ytitle("Probability of Ranking", axis(1)) ///
	xlabel(0 (50) 300)
graph save pr_ranking2.gph, replace
graph export pr_ranking2.png, replace

twoway hist deficit_rc, width(20) frequency yaxis(2) bcolor(navy*.2) ///
	|| line p3 deficit if tie1 == 5 & pred == 1, lwidth(0.6) lcolor(red*1) ///
	|| line p3 deficit if tie1 == 4 & pred == 1, lwidth(0.6) lcolor(red*.9) ///
	|| line p3 deficit if tie1 == 3 & pred == 1, lwidth(0.6) lcolor(red*.7) ///
	|| line p3 deficit if tie1 == 2 & pred == 1, lwidth(0.6) lcolor(red*.5) ///
	|| line p3 deficit if tie1 == 1 & pred == 1, lwidth(0.6) lcolor(red*.3) ///
	|| line p3 deficit if tie1 == 0 & pred == 1, lwidth(0.6) lcolor(red*0.1) ///
	legend(off) graphregion(color(white)) ///
	xtitle("Deficit") ytitle("Number of Provinces", axis(2)) ytitle("Probability of Ranking", axis(1)) ///
	xlabel(0 (50) 300)
graph save pr_ranking3.gph, replace
graph export pr_ranking3.png, replace

/* Table 2: multinomial logistic regression analysis of Central-Committee membership */

use membership, clear


global control "age male minority experience1 experience2 work_units tie1 tie3 tie4"

mlogit member deficit $control, cluster(province) base(0)
estimates store m5

estout m5, cell(b (star fmt(4)) se (par fmt(4))) ///
	stats(N ll pr2) starl(* .05 ** .01)

/* Figure 2: Estimated effect of deficits on Central-Committee membership */

* Set up the covariates
set more off
clear
set obs 1

gen age = 54
gen male = 1
gen minority = 0
gen experience1 = 62
gen experience2 = 14
gen work_units = 1
gen tie1 = 1.6
gen tie3 = 0.4
gen tie4 = 0.3

expand 301
gen deficit = _n - 1
gen id = _n

gen pred = 1

compress
save temp, replace

* Estimate the probabilities of membership status

use membership, clear

global control "age male minority experience1 experience2 work_units tie1 tie3 tie4"

mlogit member deficit $control, cluster(province) base(0)

append using temp

predict p0, outcome(0) 
predict p1, outcome(1) 
predict p2, outcome(2) 
predict p3, outcome(3) 

erase temp.dta

* Visualize the estimated probabilities of membership status

bysort province: gen deficit_rc = deficit if _n == 1
replace deficit_rc = 300 if !missing(deficit_rc) & deficit_rc >= 300

twoway hist deficit_rc, width(20) frequency yaxis(2) bcolor(navy*.2) ///
	|| line p1 deficit if pred == 1, lwidth(0.6) lcolor(black) lpattern(dot) sort ///
	|| line p2 deficit if pred == 1, lwidth(0.6) lcolor(black) lpattern(dash) sort ///
	|| line p3 deficit if pred == 1, lwidth(0.6) lcolor(black) lpattern(solid) sort ///
	graphregion(color(white)) ///
	xtitle("Deficit") ytitle("Number of Provinces", axis(2)) ytitle("Probability of Membership Status", axis(1)) ///
	xlabel(0 (50) 300) ///
	legend(rows(2) region(color(white)) label(1 "Frequency") ///
	label(2 "Alternate member") label(3 "Full member") label(4 "Politburo member"))
graph save pr_membership.gph, replace
graph export pr_membership.png, replace	

/* Appendix 1: Summary statistics provincial leaders */

use ranking, clear

tabstat age male minority tie1 tie2 seniority experience1 experience2 work_units tie3 tie4 ranking, ///
	columns(statistics) statistics(n mean median sd min max)
